/*     */ package com.zimbra.cs.mailbox.calendar;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.mailbox.CalendarItem.Instance;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class OrganizerInviteChanges
/*     */ {
/*     */   private final Invite oldInvite;
/*     */   public final Invite newInvite;
/*  34 */   private List<CalendarItem.Instance> newExdates = null;
/*  35 */   private List<CalendarItem.Instance> oldExdates = null;
/*  36 */   private List<CalendarItem.Instance> exdatesOnlyInNew = null;
/*  37 */   private List<CalendarItem.Instance> exdatesOnlyInOld = null;
/*  38 */   private List<ZAttendee> attendeesOnlyInNew = null;
/*  39 */   private List<ZAttendee> attendeesOnlyInOld = null;
/*  40 */   private InviteChanges changes = null;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public OrganizerInviteChanges(Invite oldInvite, Invite newInvite)
/*     */   {
/*  47 */     this.oldInvite = oldInvite;
/*  48 */     this.newInvite = newInvite;
/*  49 */     if ((oldInvite != null) && (newInvite != null)) {
/*  50 */       this.changes = new InviteChanges(oldInvite, newInvite);
/*     */     }
/*     */   }
/*     */   
/*     */   public String getSubject() {
/*  55 */     if (this.newInvite != null)
/*  56 */       return this.newInvite.getName();
/*  57 */     if (this.oldInvite != null) {
/*  58 */       return this.oldInvite.getName();
/*     */     }
/*  60 */     return "";
/*     */   }
/*     */   
/*     */   public boolean inviteCanceled() {
/*  64 */     return (this.newInvite == null) && (this.oldInvite != null);
/*     */   }
/*     */   
/*     */   public boolean isReplyInvalidatingChange() {
/*  68 */     if (this.changes == null) {
/*  69 */       return true;
/*     */     }
/*  71 */     return this.changes.isReplyInvalidatingChange();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean isChanged()
/*     */   {
/*  79 */     if ((this.newInvite == null) && (this.oldInvite == null)) {
/*  80 */       return false;
/*     */     }
/*  82 */     if ((this.oldInvite == null) || (this.newInvite == null)) {
/*  83 */       return true;
/*     */     }
/*  85 */     if (!this.changes.noChange()) {
/*  86 */       ZimbraLog.calendar.trace("changes.noChange()=false for invite %s", new Object[] { this.newInvite.toString() });
/*  87 */       return true;
/*     */     }
/*  89 */     if (!getExdatesOnlyInNew().isEmpty()) {
/*  90 */       ZimbraLog.calendar.trace("isChanged=true (new EXDATEs) for invite %s", new Object[] { this.newInvite.toString() });
/*  91 */       return true;
/*     */     }
/*  93 */     if (!getExdatesOnlyInOld().isEmpty()) {
/*  94 */       ZimbraLog.calendar.trace("isChanged=true (old EXDATEs) for invite %s", new Object[] { this.newInvite.toString() });
/*  95 */       return true;
/*     */     }
/*  97 */     if (!getAttendeesOnlyInNew().isEmpty()) {
/*  98 */       ZimbraLog.calendar.trace("isChanged=true (new ATTENDEEs) for invite %s", new Object[] { this.newInvite.toString() });
/*  99 */       return true;
/*     */     }
/* 101 */     if (!getAttendeesOnlyInOld().isEmpty()) {
/* 102 */       ZimbraLog.calendar.trace("isChanged=true (old ATTENDEEs) for invite %s", new Object[] { this.newInvite.toString() });
/* 103 */       return true;
/*     */     }
/* 105 */     ZimbraLog.calendar.trace("isChanged=false for invite %s", new Object[] { this.newInvite.toString() });
/* 106 */     return false;
/*     */   }
/*     */   
/*     */   public List<CalendarItem.Instance> getNewExdates() {
/* 110 */     if (this.newExdates == null) {
/* 111 */       this.newExdates = Invite.getExdates(this.newInvite);
/*     */     }
/* 113 */     return this.newExdates;
/*     */   }
/*     */   
/*     */   public List<CalendarItem.Instance> getOldExdates() {
/* 117 */     if (this.oldExdates == null) {
/* 118 */       this.oldExdates = Invite.getExdates(this.oldInvite);
/*     */     }
/* 120 */     return this.oldExdates;
/*     */   }
/*     */   
/*     */   public List<CalendarItem.Instance> getExdatesOnlyInFirst(List<CalendarItem.Instance> first, List<CalendarItem.Instance> second) {
/* 124 */     List<CalendarItem.Instance> newList = Lists.newArrayList(first);
/* 125 */     Iterator<CalendarItem.Instance> iter = newList.iterator();
/* 126 */     CalendarItem.Instance curr; while (iter.hasNext()) {
/* 127 */       curr = (CalendarItem.Instance)iter.next();
/* 128 */       for (CalendarItem.Instance fromSecond : second) {
/* 129 */         if (fromSecond.sameTime(curr)) {
/* 130 */           iter.remove();
/* 131 */           break;
/*     */         }
/*     */       }
/*     */     }
/* 135 */     return newList;
/*     */   }
/*     */   
/*     */   public List<CalendarItem.Instance> getExdatesOnlyInNew() {
/* 139 */     if (this.exdatesOnlyInNew == null) {
/* 140 */       this.exdatesOnlyInNew = getExdatesOnlyInFirst(getNewExdates(), getOldExdates());
/*     */     }
/* 142 */     return this.exdatesOnlyInNew;
/*     */   }
/*     */   
/* 145 */   public List<CalendarItem.Instance> getExdatesOnlyInOld() { if (this.exdatesOnlyInOld == null) {
/* 146 */       this.exdatesOnlyInOld = getExdatesOnlyInFirst(getOldExdates(), getNewExdates());
/*     */     }
/* 148 */     return this.exdatesOnlyInOld;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public List<ZAttendee> getAttendeesOnlyInFirst(List<ZAttendee> first, List<ZAttendee> second)
/*     */   {
/* 155 */     if (first == null) {
/* 156 */       return Lists.newArrayListWithCapacity(0);
/*     */     }
/* 158 */     List<ZAttendee> newList = Lists.newArrayList(first);
/* 159 */     if (second == null) {
/* 160 */       return newList;
/*     */     }
/* 162 */     Iterator<ZAttendee> iter = newList.iterator();
/* 163 */     ZAttendee curr; while (iter.hasNext()) {
/* 164 */       curr = (ZAttendee)iter.next();
/* 165 */       for (ZAttendee fromSecond : second) {
/* 166 */         if (fromSecond.addressesMatch(curr)) {
/* 167 */           iter.remove();
/* 168 */           break;
/*     */         }
/*     */       }
/*     */     }
/* 172 */     return newList;
/*     */   }
/*     */   
/*     */   public List<ZAttendee> getAttendeesOnlyInNew() {
/* 176 */     if (this.attendeesOnlyInNew == null) {
/* 177 */       this.attendeesOnlyInNew = getAttendeesOnlyInFirst(this.newInvite == null ? null : this.newInvite.getAttendees(), this.oldInvite == null ? null : this.oldInvite.getAttendees());
/*     */     }
/*     */     
/*     */ 
/* 181 */     return this.attendeesOnlyInNew;
/*     */   }
/*     */   
/*     */   public List<ZAttendee> getAttendeesOnlyInOld() {
/* 185 */     if (this.attendeesOnlyInOld == null) {
/* 186 */       this.attendeesOnlyInOld = getAttendeesOnlyInFirst(this.oldInvite == null ? null : this.oldInvite.getAttendees(), this.newInvite == null ? null : this.newInvite.getAttendees());
/*     */     }
/*     */     
/*     */ 
/* 190 */     return this.attendeesOnlyInOld;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/calendar/OrganizerInviteChanges.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */